using JSON
include("lib.jl")

conf = read("../data/conf.json", String) |> JSON.Parser.parse

function genInfoDicts(gp::Function, st::Function, path::String)
    files = readdir(path) |> st
    dircs = Array{Dict, 1}(undef, length(files))
    for i = 1:length(files)
        dircs[i] = readlines(gp(files[i])) |> parseini
    end
    return (name=files, info=dircs)
end

# building
buildings = genInfoDicts(x->joinpath(conf["root"], "buildings_types", x), x->x[occursin.("ini", x)], joinpath(conf["root"], "buildings_types"))
# airplanes
airplanes = genInfoDicts(x->joinpath(conf["root"], "airplanes", x, "script.ini"), x->x, joinpath(conf["root"], "airplanes"))
# trains
trains = genInfoDicts(x->joinpath(conf["root"], "trains", x, "script.ini"),
    x->x[map(y->isdir(joinpath(conf["root"], "trains", y)), x)],
    joinpath(conf["root"], "trains"))
# ships
ships = genInfoDicts(x->joinpath(conf["root"], "ships", x, "script.ini"), x->x, joinpath(conf["root"], "ships"))
# vehicles
vehicles = genInfoDicts(x->joinpath(conf["root"], "vehicles", x, "script.ini"), x->x, joinpath(conf["root"], "vehicles"))
